﻿package mortal.game.view.firstReCharge
{
    import Message.Game.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.mvc.core.*;

    public class FirstRechargeController extends Controller
    {
        public static var firstRechargeDay:int = 11;

        public function FirstRechargeController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.FirstRechargeUpdate, this.updateFirstRechargeInfo);
            NetDispatcher.addCmdListener(ServerCommand.NewDayUpdate, this.updateFirstRechargeInfo);
            Dispatcher.addEventListener(EventName.FirstRechargeWinOpen, this.openWin);
            return;
        }// end function

        private function openWin(event:DataEvent) : void
        {
            var _loc_2:int = 0;
            if (event.data)
            {
                _loc_2 = int(event.data);
            }
            else
            {
                _loc_2 = ClockManager.instance.serverOpenDateNum;
            }
            firstRechargeDay = FirstRechargeModule.rewardArr.length;
            if (_loc_2 <= firstRechargeDay)
            {
                if (FirstRechargeModule.isViewShow)
                {
                    FirstRechargeModule.instance.hide();
                }
                else
                {
                    FirstRechargeModule.instance.show();
                    if (event.data)
                    {
                        FirstRechargeModule.instance.serverOpenDay = int(event.data);
                    }
                    else
                    {
                        FirstRechargeModule.instance.serverOpenDay = ClockManager.instance.serverOpenDateNum;
                    }
                }
            }
            else if (FirstRechargeDailyModule.isViewShow)
            {
                FirstRechargeDailyModule.instance.hide();
            }
            else
            {
                FirstRechargeDailyModule.instance.show();
                if (event.data)
                {
                    FirstRechargeDailyModule.instance.serverOpenDay = int(event.data);
                }
                else
                {
                    FirstRechargeDailyModule.instance.serverOpenDay = ClockManager.instance.serverOpenDateNum;
                }
            }
            return;
        }// end function

        private function updateFirstRechargeInfo(param1:Object) : void
        {
            var _loc_2:* = Cache.instance.firstRecharge.firstRechargeRewardInfo;
            var _loc_3:* = ClockManager.instance.serverOpenDateNum;
            if (_loc_2)
            {
                if (_loc_2.isGet)
                {
                    if (FirstReChargeIcon.isViewShow)
                    {
                        FirstReChargeIcon.instance.hide();
                    }
                }
                else
                {
                    FirstReChargeIcon.instance.show();
                    FirstReChargeIcon.instance.setLeftTimeAndState(ClockManager.instance.todayLeftMillisecond * 0.001, 1, "hh:mm:ss", false);
                    FirstReChargeIcon.instance.playEffect();
                    if (_loc_2.rechargeNum > 0 && !_loc_2.isGet)
                    {
                        if (Game.isSceneInit())
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideActiveByEvent, {mainId:47, stepId:1}));
                        }
                        else
                        {
                            Dispatcher.addEventListener(EventName.Scene_Update, this.updateFirstRechargeInfo);
                        }
                    }
                }
                if (_loc_3 <= 7)
                {
                    if (FirstRechargeModule.isViewShow)
                    {
                        FirstRechargeModule.instance.hide();
                    }
                }
                else if (FirstRechargeDailyModule.isViewShow)
                {
                    FirstRechargeDailyModule.instance.hide();
                }
            }
            return;
        }// end function

    }
}
